<template>
<div class="box-padding">
    <div class="role-title">
        选择项目
    </div>
    <Row style="padding-top:30px;">
        <Col span="16" offset="4">
        <Row :gutter="16">
            <Col span="20">
            <Input v-model="projectName" placeholder="请选择项目" />
            </Col>
            <Col span="4">
            <Button type="primary" @click="projectGetAll">搜索</Button>
            </Col>
        </Row>
        </Col>
    </Row>
    <Row style="padding-top:30px;">
        <Col span="16" offset="4">
        <Table :columns="columns1" :data="data1" @on-row-click="toggleTableExpand" ref="tableExpand"></Table>
        </Col>
    </Row>
</div>
</template>

<script>
import closeTag from '../../../mixins/closeTag'
import {
    mapMutations
} from 'vuex'
export default {
    mixins: [closeTag],
    data() {
        return {
            projectName: '',
            columns1: [{
                    title: '项目名称',
                    align: 'center',
                    key: 'name'
                },
                {
                    title: '管理单位',
                    key: 'manageEntName',
                    align: 'center',
                    render: (h, params) => {
                        return h('div', [
                            h(
                                'Button', {
                                    props: {
                                        type: 'text',
                                        size: 'small'
                                    }
                                },
                                params.row.projectManage.manageEntName
                            )
                        ])
                    }
                }
            ],
            data1: []
        }
    },
    computed: {},
    mounted() {
        this.projectGetAll()
    },
    methods: {
        ...mapMutations(['SET_PROJECT']),
        projectGetAll() {
            let parmes = {
                shortName: this.projectName,
                cascade:true,
                isQueryJurProject:true
            }
            this.$api.UnitProject.projectGetAll(parmes).then(resp => {
                if (resp.code == 200) {
                    this.data1 = resp.data
                }
            })
        },
        toggleTableExpand(row, index) {
            row.title = row.name
            row.loading = false
            row.children = []
            let data = JSON.stringify(row)
            this.$router.push({
                name: 'unit-project',
                query: {
                    res: data
                }
            })
            setTimeout(() => {
                this.closetab('project-list')
            }, 500)
        }
    }
}
</script>
